<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>URL测试页面</title>
    <script src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
</head>
<body>
    <h1>URL测试页面</h1>
    <div id="urlInfo"></div>
    <div id="jsConfigInfo"></div>
    <button onclick="testJsConfig()">测试JS-SDK配置</button>
    <button onclick="testPayment()">测试支付</button>

    <script>
        // 显示URL信息
        function showUrlInfo() {
            const urlInfo = document.getElementById('urlInfo');
            urlInfo.innerHTML = `
                <h3>当前URL信息：</h3>
                <p>完整URL: ${window.location.href}</p>
                <p>协议: ${window.location.protocol}</p>
                <p>主机: ${window.location.host}</p>
                <p>路径: ${window.location.pathname}</p>
                <p>查询参数: ${window.location.search}</p>
                <p>Hash: ${window.location.hash}</p>
                <p>去除Hash后的URL: ${window.location.href.split('#')[0]}</p>
            `;
        }

        // 测试JS-SDK配置
        async function testJsConfig() {
            try {
                const currentUrl = window.location.href.split('#')[0];
                console.log('测试URL:', currentUrl);
                
                const response = await fetch(`https://ai.huixinqi.cn/app/aihaowu/order/js_config?url=${encodeURIComponent(currentUrl)}`, {
                    headers: {
                        'Authorization': 'Bearer test_token'
                    }
                });
                
                const result = await response.json();
                console.log('JS-SDK配置结果:', result);
                
                const jsConfigInfo = document.getElementById('jsConfigInfo');
                jsConfigInfo.innerHTML = `
                    <h3>JS-SDK配置结果：</h3>
                    <pre>${JSON.stringify(result, null, 2)}</pre>
                `;
                
                if (result.code === 0) {
                    // 配置微信JS-SDK
                    wx.config({
                        debug: true,
                        appId: result.data.appId,
                        timestamp: result.data.timestamp,
                        nonceStr: result.data.nonceStr,
                        signature: result.data.signature,
                        jsApiList: ['chooseWXPay']
                    });
                    
                    wx.ready(() => {
                        console.log('微信JS-SDK配置成功');
                        alert('微信JS-SDK配置成功！');
                    });
                    
                    wx.error((res) => {
                        console.error('微信JS-SDK配置失败', res);
                        alert('微信JS-SDK配置失败: ' + JSON.stringify(res));
                    });
                }
            } catch (error) {
                console.error('测试失败:', error);
                alert('测试失败: ' + error.message);
            }
        }

        // 测试支付
        async function testPayment() {
            try {
                const response = await fetch('https://ai.huixinqi.cn/app/aihaowu/order/create', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json',
                        'Authorization': 'Bearer test_token'
                    }
                });
                
                const result = await response.json();
                console.log('支付测试结果:', result);
                alert('支付测试结果: ' + JSON.stringify(result));
            } catch (error) {
                console.error('支付测试失败:', error);
                alert('支付测试失败: ' + error.message);
            }
        }

        // 页面加载时显示URL信息
        window.onload = function() {
            showUrlInfo();
        };
    </script>
</body>
</html> 